<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/common/jsp/declare.jsp" %>

<!DOCTYPE html>
<html>
<head>
	<base href="<%=basePath %>" />
	<title>房间-编辑</title>
	<%@ include file="/common/jsp/common.jsp" %>
	
	<script>
	function rowEdit() {
		redirect("mvc/main/bedList.htm");
	}
	function validate(form) {
		var success = true;
		$(form).find("input").each(function(){
			if (success && !$(this).val()) {
				var _input = this;
				jAlert("请填写完整信息", function(){
					_input.focus();
				});
				success = false;
			}
		});
		return success;
	}
	
	function deleteRoom() {
		jConfirm("确认删除？", function(yes){
			if (!yes)
				return;
			
			doAjax({
				url: addFromUserName("mvc/main/${roomId}/${!empty room and !empty room.id ? room.id : 0}/roomDel.json"),
				success: function(json){
					if (json && json.msg){
						jAlert(json.msg);
						if (json && json.success)
							redirect("mvc/main/${roomId}/roomList.htm");
					} else {
						jAlert("删除失败");
					}
				}
			});
		});
	}
	</script>
</head>
<body id="room" class="bg-grey">
	<div class="picBar">
		<img src="aizu/images/room/room.jpg" />
	</div>
	<form action="mvc/main/${roomId}/${!empty room and !empty room.id ? room.id : 0}/roomEdit.htm"
		method="post" onsubmit="return validate(this);">
		<input type="hidden" name="fromUserName" value="${param.fromUserName }" />
		<div class="frame">
			<div class="row">
				<div class="input" placeholder="房屋地址">${address }</div>
			</div>
			<div class="row">
				<input name="room_num" value="${room.name }" class="input" placeholder="输入房间名称" />
			</div>
		</div>
		<div class="button-bar center">
			<input type="submit" value="保存" class="submit" />
			<c:if test="${!empty room.id }">
			<input type="button" value="删除" class="delete" onclick="deleteRoom()" />
			</c:if>
		</div>
	</form>
</body>
</html>